﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using PowerCreator.LMS.Common.Script;

//using PowerCreator.LMS.Logic.Common;
//using PowerCreator.LMS.Model.Entity;
//using PowerCreator.LMS.Logic.PaperManager;
//using PowerCreator.LMS.Logic.QuestionManager;

public partial class sysadmin_CountManager_QuestionInfo : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerQuestionTypeInfo objQuestionTypeLogic=new ManagerQuestionTypeInfo();
    //ManagerPaperUserAnswer objPaperUserAnswerLogic=new ManagerPaperUserAnswer();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.CountQuestion))
        //{
        //    Script.ShowAndHistory("您没有试题统计的权限!", -1);
        //    return;
        //}
        //if (!IsPostBack)
        //{
        //    BandQuestiontype();
        //    string search = GetSearch();
        //    BinderPager(search);
        //    BinderGV(search, 1);
        //}
    }
    private void BandQuestiontype()
    {
        //dpdlst_questiontype.DataSource = objQuestionTypeLogic.Query("");
        //dpdlst_questiontype.DataTextField = "QuestionTypeName";
        //dpdlst_questiontype.DataValueField = "TypeID";
        //dpdlst_questiontype.DataBind();
    }
    private string GetSearch()
    {
        String search ="";
        if (!string.IsNullOrEmpty(txtQuestionContent.Text.Trim()))
        {
            search = string.Format(" and QuestionContent like '%{0}%' ", txtQuestionContent.Text);
        }
        if (dpdlst_questiontype.SelectedValue != "-1")
        {
            search += string.Format(" and QuestionTypeID = {0} ", dpdlst_questiontype.SelectedValue);
        }
        return search;
    }
    private void BinderPager(string search)
    {
        //AspNetPager1.RecordCount = objPaperUserAnswerLogic.QuestionCountListCount(search);
        //AspNetPager1.PageSize = FBasePage.PageSize();
    }
    private void BinderGV(string search, int pageIndex)
    {
        //DataTable dt = new DataTable();
        //dt = objPaperUserAnswerLogic.QuestionCountList(search, pageIndex, FBasePage.PageSize());
        //ViewState["dt"] = dt;
        //gvQuestionList.DataSource = dt;
        //gvQuestionList.DataBind();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
    protected void gvPaperList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string url = string.Empty;
        if (e.CommandName == "btn_sel")
        {
            url = "FCQuestionPass.aspx?q=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }

    }
    protected void gvQuestionList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("bgColor", "#F7FAFF");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FAEDB8'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7FAFF'");

            LinkButton btn_sel = (LinkButton)e.Row.Cells[5].FindControl("btn_sel");
            switch (e.Row.Cells[2].Text.Trim())
            {
                case "1": e.Row.Cells[2].Text = GetLanageValueByKey("msg_CelueSelectQuest_panduanti", PowerCreator.LMS.Language.LanagetItemType.Page);
                    break;
                case "2": e.Row.Cells[2].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Danxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
                    break;
                case "3": e.Row.Cells[2].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Duoxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
                    //btn_sel.Enabled = false;
                    break;
                case "4": e.Row.Cells[2].Text = GetLanageValueByKey("msg_CelueSelectQuest_tiankongti", PowerCreator.LMS.Language.LanagetItemType.Page);
                    //btn_sel.Enabled = false;
                    break;
                case "5": e.Row.Cells[2].Text = GetLanageValueByKey("lab_EditUserPaper_Question_Mingcijieshiti", PowerCreator.LMS.Language.LanagetItemType.Page);
                    //btn_sel.Enabled = false;
                    break;
                default: e.Row.Cells[2].Text = GetLanageValueByKey("msg_CelueSelectQuest_jiandati", PowerCreator.LMS.Language.LanagetItemType.Page);
                    //btn_sel.Enabled = false;
                    break;
            }
        }
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        
        //DataTable dt = (DataTable)ViewState["dt"];
        //ExportList(dt);
    }
    private void ExportList(DataTable dt)
    {
        //ArrayList list = new ArrayList();
        //for (int i = 0; i < dt.Columns.Count; i++)
        //{
        //    if (dt.Columns[i].ColumnName == "QuestionID")
        //    {
        //        dt.Columns[i].ColumnName = "试题ID";
        //        dt.Columns[i].SetOrdinal(0);
        //    }
        //    else if (dt.Columns[i].ColumnName == "QuestionContent")
        //    {
        //        dt.Columns[i].ColumnName = "试题内容";
        //        dt.Columns[i].SetOrdinal(1);
        //    }
        //    else if (dt.Columns[i].ColumnName == "QuestionTypeID")
        //    {
        //        dt.Columns[i].ColumnName = "试题类型";
        //        dt.Columns[i].SetOrdinal(2);
        //    }
        //    else if (dt.Columns[i].ColumnName == "UserCount")
        //    {
        //        dt.Columns[i].ColumnName = "答题总人数";
        //        dt.Columns[i].SetOrdinal(3);
        //    }
        //    else if (dt.Columns[i].ColumnName == "RightCount")
        //    {
        //        dt.Columns[i].ColumnName = "答题正确数";
        //        dt.Columns[i].SetOrdinal(4);
        //    }
        //    else
        //    {
        //        list.Add(dt.Columns[i].ColumnName);
        //    }
        //}
        //for (int i = 0; i < list.Count; i++)
        //{
        //    dt.Columns.Remove(list[i].ToString());
        //}
        //Excel objExcel = new Excel();
        //objExcel.ToExcel(dt, this.Page, "试题统计", "试题统计信息", "QuestionInfo");
    }
    protected void btnExport_All_Click(object sender, EventArgs e)
    {
        //string search = GetSearch();
        //DataTable dt = new DataTable();
        //dt = objPaperUserAnswerLogic.QuestionCountList(search, 1, objPaperUserAnswerLogic.QuestionCountListCount(search));
        //ExportList(dt);
    }
}
